package cn.wolfcode.trip.app.web.inspector;

import cn.wolfcode.trip.app.util.UserContext;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author by mycp
 * @Classname LoginInspector
 * @Description TODO
 * @Date 2018/11/1 18:48
 */
public class LoginInspector extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 获取当前用户, 并判断当前用户是否已经登录过
        if (UserContext.getCurrentUser() == null) {
            // 没登录, 重定向回去登录界面
            response.sendRedirect("/login.html");
            // 不放行
            return false;
        }
        // 登录过放行
        return true;
    }
}
